package com.example.leaderapplication.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.leaderapplication.Bean.AddShiftsInfoRequsetBean;
import com.example.leaderapplication.Bean.LimitDataBean;
import com.example.leaderapplication.R;

import java.util.List;

public class BanCiNoTimeListAdapter extends RecyclerView.Adapter<BanCiNoTimeListAdapter.ViewHolder> {

    private Context context;
    private List<AddShiftsInfoRequsetBean.LimitDateListBean> dataList;
    private dataSizeListener dataListener;

    public BanCiNoTimeListAdapter(Context context, List<AddShiftsInfoRequsetBean.LimitDateListBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_banci_no_time, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.title.setText("无效时段" + position);
        holder.message.setText(dataList.get(position).getStartLimitDate() + "至" + dataList.get(position).getEndLimitDate());
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dataList.remove(position);
                notifyDataSetChanged();
                if (dataList.size() <= 0) {
                    dataListener.dataSize(dataList.size());
                }
            }
        });
    }

    public interface dataSizeListener{
        void dataSize(int size);
    }

    public void setDataSizeListener(dataSizeListener dataSizeListener){
        dataListener = dataSizeListener;
    }



    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView title;
        private final TextView message;
        private final TextView delete;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.tv_notime_title);
            message = itemView.findViewById(R.id.tv_notime_message);
            delete = itemView.findViewById(R.id.tv_notime_delete);
        }
    }
}
